package me.zzp.mapper;

import me.zzp.domain.Condition;
import me.zzp.domain.Pageable;
import me.zzp.model.User;
import me.zzp.provider.DynamicConditionProvider;
import me.zzp.provider.UserSqlProvider;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import java.util.List;
import java.util.Map;

/**
 * @author zhangzepeng
 */
public interface UserMapper {

    @SelectProvider(type = UserSqlProvider.class, method = "countBy")
    int countBy(@Param(DynamicConditionProvider.PREFIX_CONDITION) Condition condition,
                @Param(DynamicConditionProvider.PREFIX_PARAMETER) Map<String, Object> parameter);

    @SelectProvider(type = UserSqlProvider.class, method = "findBy")
    List<User> findAllBy(@Param(DynamicConditionProvider.PREFIX_CONDITION) Condition condition,
                         @Param(DynamicConditionProvider.PREFIX_PARAMETER) Map<String, Object> parameter,
                         @Param(DynamicConditionProvider.PREFIX_PAGEABLE) Pageable pageable);

    @Select("select * from users where id = #{id} limit 1")
    User findOne(int id);

    @Insert("insert into users (name) values (#{name})")
    int create(User user);

    @UpdateProvider(type = UserSqlProvider.class, method = "updateBy")
    int updateBy(@Param(DynamicConditionProvider.PREFIX_CONDITION) Condition condition,
                 @Param(DynamicConditionProvider.PREFIX_PARAMETER) Map<String, Object> parameter,
                 @Param("user") User user);

    @DeleteProvider(type = UserSqlProvider.class, method = "deleteBy")
    int destroyBy(@Param(DynamicConditionProvider.PREFIX_CONDITION) Condition condition,
                  @Param(DynamicConditionProvider.PREFIX_PARAMETER) Map<String, Object> parameter);
}
